using System;

using MettleSystems.dashCommerce.Core;
using MettleSystems.dashCommerce.Core.Caching;
using MettleSystems.dashCommerce.Core.Configuration;
using MettleSystems.dashCommerce.Store.Services;
using MettleSystems.dashCommerce.Store.Services.PaymentService;

namespace MettleSystems.dashCommerce.Web.admin
{
	public partial class paymentserviceconfiguration : MettleSystems.dashCommerce.Controls.AdminPage
	{

		#region Page Events

		/// <summary>
		/// Handles the Load event of the Page control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void Page_Load(object sender, EventArgs e)
		{
		}

		/// <summary>
		/// Handles the Click event of the btnSave control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void btnSave_Click(object sender, EventArgs e)
		{
			try {
				PaymentServiceSettings paymentServiceSettings = new PaymentServiceSettings();
				ProviderSettings settings = new ProviderSettings();
				settings.Name = typeof (PayPalProPaymentProvider).Name;
				settings.Type = typeof (PayPalProPaymentProvider).AssemblyQualifiedName;
				settings.Parameters.Add("ApiUserName", "username");
				settings.Parameters.Add("ApiPassword", "password");
				settings.Parameters.Add("Signature", "signature");
				settings.Parameters.Add("IsLive", "false");
				paymentServiceSettings.ProviderSettingsCollection.Add(settings);
				DatabaseConfigurationProvider config = new DatabaseConfigurationProvider();
				config.SaveConfiguration(PaymentServiceSettings.SECTION_NAME, paymentServiceSettings, WebUtility.GetUserName());
				SiteSettingCache.RemoveSiteSettingsFromCache();
			}
			catch (Exception ex) {
				Logger.Error(typeof (paymentserviceconfiguration).Name + ".Page_Load", ex);
				Master.MessageCenter.DisplayCriticalMessage(ex.Message);
			}
		}

		#endregion

	}
}
